home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 32 / Mac Magazin and MacEasy Magazine CD - Issue 32.iso / Multimedia / PlayerPRO 4.5.5 Dev.Kit / Plug-Ins / Digital Editor Plugs / NoteTrans.c < prev    next >
C/C++ Source or Header  |  1995-09-23  |  3KB  |  156 lines

  1. /*    Note Translate    */
  2. /*    v 1.0            */
  3. /*    1995 by ANR        */
  4.  
  5. //    Usage:
  6. //    A small example of to use Digital Editor Plugs with a MODAL DIALOG
  7.  
  8. #include "MAD.h"
  9. #include "PPPlug.h"
  10.  
  11. #if defined(powerc) || defined(__powerc)
  12. enum {
  13.         PlayerPROPlug = kCStackBased
  14.         | RESULT_SIZE(SIZE_CODE( sizeof(OSErr)))
  15.         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof( Pcmd*)))
  16.         | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof( PPInfoPlug*)))
  17. };
  18.  
  19. ProcInfoType __procinfo = PlayerPROPlug;
  20. #else
  21. #include <A4Stuff.h>
  22. #endif
  23.  
  24. /** Utils Functions **/
  25.  
  26. void GetDText (DialogPtr dlog, short item, StringPtr str)
  27. {
  28. Handle    itemHandle;
  29. short    itemType;
  30. Rect    itemRect;
  31.  
  32.     GetDItem (dlog, item, &itemType, &itemHandle, &itemRect);
  33.     GetIText (itemHandle, str);
  34. }
  35.  
  36. void SetDText (DialogPtr dlog, short item, Str255 str)
  37. {
  38. Handle    itemHandle;
  39. short    itemType;
  40. Rect    itemRect;
  41.  
  42.     GetDItem (dlog, item, &itemType, &itemHandle, &itemRect);
  43.     SetIText (itemHandle, str);
  44. }
  45.  
  46. GDHandle    TheGDevice:0xCC8;
  47.  
  48. void AutoPosition( DialogPtr aDia)
  49. {
  50.     Point    Position, mouse;
  51.     Rect    ViewRect;
  52.     short    XSize = (aDia->portRect.right - aDia->portRect.left), YSize = (aDia->portRect.bottom - aDia->portRect.top);
  53.     
  54.     GetMouse( &mouse);
  55.     LocalToGlobal( &mouse);
  56.     
  57.     SetRect( &ViewRect, (*TheGDevice)->gdRect.left + 8, (*TheGDevice)->gdRect.top + 43,
  58.                         (*TheGDevice)->gdRect.right - 8, (*TheGDevice)->gdRect.bottom - 8);
  59.     
  60.     Position.h = mouse.h - XSize/2;
  61.     if( Position.h + XSize >= ViewRect.right) Position.h = ViewRect.right - XSize;
  62.     else if( Position.h <= ViewRect.left) Position.h = ViewRect.left;
  63.     
  64.     Position.v = mouse.v - YSize/2;
  65.     if( Position.v + YSize >= ViewRect.bottom) Position.v = ViewRect.bottom - YSize;
  66.     else if( Position.v <= ViewRect.top) Position.v = ViewRect.top;
  67.     
  68.     MoveWindow( aDia, Position.h, Position.v, false);
  69.     
  70.     ShowWindow( aDia);
  71. }
  72.  
  73. Cmd* GetCmd( short row, short    track, Pcmd*    myPcmd)
  74. {
  75.     if( row < 0) row = 0;
  76.     else if( row >= myPcmd->length) row = myPcmd->length -1;
  77.  
  78.     if( track < 0) track = 0;
  79.     else if( track >= myPcmd->tracks) track = myPcmd->tracks -1;
  80.     
  81.     return( &(myPcmd->myCmd[ (myPcmd->length * track) + row]));
  82. }
  83.  
  84. /** Main function **/
  85.  
  86. OSErr main(     Pcmd                    *myPcmd,
  87.                 PPInfoPlug                *thePPInfoPlug)
  88. {
  89.     DialogPtr            myDia;
  90.     short                itemHit;
  91.     Str255                tStr;
  92.     
  93. #ifndef powerc
  94.     long    oldA4 = SetCurrentA4();             //this call is necessary for strings in 68k code resources
  95. #endif
  96.  
  97.     myDia = GetNewDialog( 128, 0L, (WindowPtr) -1L);
  98.     SetPort( myDia);
  99.     AutoPosition( myDia);
  100.  
  101.     SetDText( myDia, 3, "\p0");
  102.     SelIText( myDia, 3, 0, 200);
  103.     
  104.     do
  105.     {
  106.         RESTART:
  107.     
  108.         #if defined(powerc) || defined(__powerc)
  109.         ModalDialog( thePPInfoPlug->MyDlgFilterUPP, &itemHit);
  110.         #else
  111.         ModalDialog( (ModalFilterProcPtr) thePPInfoPlug->MyDlgFilterUPP, &itemHit);
  112.         #endif
  113.         
  114.     }while( itemHit != 1 && itemHit != 2);
  115.     
  116.     if( itemHit == 1)
  117.     {
  118.         short    track, row;
  119.         long    trans;
  120.         Cmd        *myCmd;
  121.     
  122.         GetDText( myDia, 3, tStr);        StringToNum( tStr, &trans);
  123.         
  124.         // Check values
  125.         
  126.         if( trans < -96 || trans > 96)
  127.         {
  128.             SelIText( myDia, 3, 0, 200);
  129.             SysBeep( 1);
  130.             goto RESTART;
  131.         }
  132.         
  133.         for( track = 0; track < myPcmd->tracks; track++)
  134.         {
  135.             for( row = 0; row < myPcmd->length; row++)
  136.             {
  137.                 myCmd = GetCmd( row, track, myPcmd);
  138.                 
  139.                 if( myCmd->note != 0xFF)        // no notes = 0xFF
  140.                 {
  141.                     if( (long) myCmd->note + trans < 0) myCmd->note = 0;
  142.                     else if( (long) myCmd->note + trans >= 96) myCmd->note = 96-1;
  143.                     else myCmd->note += trans;
  144.                 }
  145.             }
  146.         }
  147.     }
  148.     
  149.     DisposDialog( myDia);
  150.     
  151.     #ifndef powerc
  152.         SetA4( oldA4);
  153.     #endif
  154.     
  155.     return noErr;
  156. }